<!-- 后台管理，左侧的权限菜单 -->
<template>
  <Layout>
    <Sider hide-trigger :style="{background: '#fff'}">
      <Menu active-name="0-0" theme="light" width="auto" :open-names="['0']">
        <Submenu :name="index" v-for="(resource, index) in resources" :key="index">
          <template slot="title">
            <Icon :type="resource.icon" size="17"></Icon>
            {{ resource.name }}
          </template>

          <MenuItem v-for="(res, indx) in resource.children" :key="indx"
                    :name="index-indx"
                    @click.native="menu_cliek(resource.name, res.name, res.url)">
            <Icon :type="res.icon" size="17"></Icon>
            {{res.name}}
          </MenuItem>

        </Submenu>
      </Menu>
    </Sider>
    <Layout :style="{padding: '0 24px 24px'}">
      <Breadcrumb :style="{margin: '24px 0'}">
        <BreadcrumbItem>{{ BreadcrumbItemOne }}</BreadcrumbItem>
        <BreadcrumbItem>{{ BreadcrumbItemTwo }}</BreadcrumbItem>
      </Breadcrumb>
      <Content :style="{background: '#fff'}">
        <component :is="which_view_to_show"
                   @childClickMenu="menu_cliek"
                   :params="params">
        </component>
      </Content>
    </Layout>
  </Layout>
</template>
<script>
  //引入用户列表组件
  import user_list from '../user/user_list'
  //引入用户编辑组织
  import user_edit from '../user/user_edit'
  //权限列表组件
  import resource_list from '../resource/resource_list'
  //引入编辑权限组件
  import resource_edit from '../resource/resource_edit'
  //引入角色列表组件
  import role_list from '../role/role_list'
  //引入角色编辑组件
  import role_edit from '../role/role_edit'
  //引入微信页
  import chat_list from '../chat/chat_list'
  //课件管理
  import lesson_list from '../lesson/lesson_list'
  //课程编辑
  import lesson_edit from '../lesson/lesson_edit'
  //生成代码的首页
  import code_list from '../code/code_list'
  //生成代码，某个表的列的列表
  import columns_list from '../code/columns_list'
  //定时任务管理
  import scheduler_list from '../scheduler/scheduler_list'
  import scheduler_edit from '../scheduler/scheduler_edit'
  //运行中的定时任务列表
  import job_list from '../scheduler/job_list'


  export default {
    created() {
      this.$http.get(this.apiUrl() + 'user/getresources/', {}, {
        emulateJSON: true
      }).then((response) => {
        if (response && response.body.success) {
          this.resources = response.body.resources;
        } else {
          if (response.body.msg === 'session-timeout') {
            window.location.href = "/";
          } else {
            this.$Notice.error({title: "错误", desc: response.body.msg});
          }
        }
      });
    },
    methods: {
      /**
       * <p>菜单点击事件，供本页调用</p>
       * @param level_1   页面导行的一级菜单
       * @param level_2   页面导行的二级菜单
       * @param url       要切换的组件名称
       */
      menu_cliek: function (level_1, level_2, url, params) {
        this.BreadcrumbItemOne = level_1;
        this.BreadcrumbItemTwo = level_2;
        this.which_view_to_show = url;
        if (null != params) {
          this.params = params;
          console.info(params)
        }
      }
    },
    data() {
      return {
        BreadcrumbItemOne: '',
        BreadcrumbItemTwo: '',
        which_view_to_show: '',
        resources: [],
        //主要用于向子组件传值
        params: {}
      }
    },
    components: {
      user_list: user_list,
      user_edit: user_edit,
      resource_list: resource_list,
      resource_edit: resource_edit,
      role_list: role_list,
      role_edit: role_edit,
      chat_list: chat_list,
      lesson_list: lesson_list,
      lesson_edit: lesson_edit,
      code_list: code_list,
      columns_list: columns_list,
      scheduler_list: scheduler_list,
      scheduler_edit: scheduler_edit,
      job_list: job_list
    }
  }
</script>
<style scoped>

</style>
